<!DOCTYPE HTML>
<html style="min-width:inherit;">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="/static/public/layer/src/css/layui.css" rel="stylesheet">
<script src="/static/public/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="/static/public/layer/src/layui.js"></script>
<script src="/static/public/layer/load_layui.js"></script>
</head>
<body>
<style>
html,body{ min-width:800px; overflow:visible; background:#FFF;}
.tiwen_box{ width:700px; padding:0 50px;}
.wtwolist ul{ margin-right:-24px;}
.wtwolist li .wtwls{ padding:10px 24px 0 0; width:120px;}
.it_wire_wt{ clear:both; overflow:hidden; padding:0 25px; border:1px solid #e4e4e4; height:50px; line-height:50px;}
.it_wire_wt input{ border:none; background:none; height:100%; width:100%;}
.bor-1aa3fa .wtwls a.curr{background-color: #1aa3fa;color: #FFF;}
</style>
<div class="tiwen_box fix fs14">
<{if $status == 1}>
<form class="layui-form layui-form-pane" method="post" action="/question/create">
	<div class="LH30 m-t30"><span id="category_box">类别：<i></i></span><span class="c-999999 r">选择一个类别，以便更好的展示您的问题</span></div>
	<input type="hidden" name="category_id" id="category_id" lay-verify="category" />
	<input type="hidden" name="category_name" id="category_name" />
	<input type="hidden" name="tid" id="tid" />
	<input type="hidden" name="tname" id="tname" />
	<div class="wtwolist bor-1aa3fa LH35 tac fix">
		<ul class="wList20">
			<{foreach from=$category_list item=category_item}>
			<li class="curr"><span class="wtwls"><a href="javascript:;" class="cate" category_id="<{$category_item.id}>"><{$category_item.name}></a></span></li>
			<{/foreach}>
		</ul>
	</div>
	<div class="LH30" style="padding: 10px 0;"><span id="topic_box">话题：<i></i></span><span class="c-999999 r">一个精准的话题更容易让相关领域的专业人士看到您的问题</span></div>
	<div class="layui-form-item">
		<div class="layui-input-inline" style="width: 558px">
			<input type="text" name="name" id="topic_name" autocomplete="off" placeholder="输入任意字符以搜索话题" class="layui-input layui-form-danger">

			<div class="layui-unselect layui-form-select layui-form-selected" style="top:-43px; display: none;" ><div class="layui-select-title"></div><dl class="layui-anim layui-anim-upbit"></dl></div>
		</div>
		<div class="layui-input-inline" style="width: 45px">
			<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-small" id="search_question_topic">搜索</a>
		</div>
		<div class="layui-input-inline" style="width: 70px">
			<a href="javascript:;" class="layui-btn layui-btn-small" id="add_question_topic"><i class="layui-icon"></i> 添加</a>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-input-block" style="margin: 0;">
			  <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="写下你的问题" class="layui-input layui-form-danger">
		</div>
	</div>

	<div class="LH20 m-t30 m-b10">问题说明（可选）：</div>
	<div class="layui-form-item layui-form-text">
		<div class="layui-input-block">
			<textarea class="layui-textarea layui-hide editor" name="content" lay-verify="content" id="editor"></textarea>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-input-inline" style="width: 590px">
			<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
		</div>
		<div class="layui-input-inline" style="width: 90px">
			<input type="checkbox" name="anonymous" value="2" title="匿名"><div class="layui-unselect layui-form-checkbox"><span>匿名</span><i class="layui-icon"></i></div>
		</div>
	</div>
	<div class="layui-form-item" style="margin: 0;">
	</div>
</form>
<{/if}>
</div>
<script>
var status = "<{$status}>";
if(status == 1){
	layui.use(['form', 'jquery', 'layedit'], function(){
		var form = layui.form(), $ = layui.jquery, layedit = layui.layedit;
		// layedit.build('editor'); //建立编辑器
		$(".cate").click(function(){
			var category_id = $(this).attr("category_id");
			var category_name = $(this).text();
			$("#category_id").val(category_id);
			$("#category_name").val(category_name);
			$("#category_box").find("i").html(category_name);
			$(".cate").removeClass("curr");
			$(this).addClass("curr");
		})
		form.verify({
			title: function(value){
				if(value.length < 5){
					return '标题不得少于得5个字符';
				}
			},category: function(value){
				if(value <= 0){
					return '请选择一个分类';
				}
			}
		});
		$("#add_question_topic").click(function(){
			var topic_name = $("#topic_name").val();
			if($.trim(topic_name) != ''){
				$.ajax({
					type:"POST",
					url:"/question/add_topic",
					dataType:"json",
					data:{"topic_name":topic_name},
					success:function(result){
						if(result.result_code == 9){
							parent.location.href = "/login";
						}else{
							$("#tid").val(result.result_data.id);
							$("#tname").val(result.result_data.name);
							$("#topic_box").find("i").html(result.result_data.name);
						}
					}
				})
			}
		})

		$("#search_question_topic").click(function(){
			var topic_name = $("#topic_name").val();
			if($.trim(topic_name) != ''){
				$.ajax({
					type:"POST",
					url:"/question/search_topic",
					dataType:"json",
					data:{"topic_name":topic_name},
					success:function(result){
						// $("#topic_box").find("i").html(result.result_data.name)
						if(result.result_code == 1){
							$(".layui-anim-upbit").empty();
							html = '';
							$.each(result.result_data, function(i, obj){ 
								if(i < result.result_data.length - 1){
									html += "<dd class='topic_dd' onclick=\"select_topic("+obj.id+", '"+obj.name+"')\" style='border-bottom:1px solid #d2d2d2;'>"+obj.name+"</dd>";
								}else{
									html += "<dd class='topic_dd' onclick=\"select_topic("+obj.id+", '"+obj.name+"')\">"+obj.name+"</dd>";
								}
							});
							$(".layui-anim-upbit").html(html);
							$(".layui-form-select").show();
						}else{
							$(".layui-anim-upbit").html('');
							$(".layui-form-select").hide();
						}
					}
				})
			}
		})
	});

	function select_topic(id, name){
		$("#tid").val(id);
		$("#tname").val(name);
		$("#topic_box").find("i").html(name);
		$(".layui-form-select").hide();
	}

	$("#topic_name").click(function(){
		if($(".layui-anim-upbit").html() != ''){
			$(".layui-form-select").show();
		}
	})
}else{
	var index = parent.layer.getFrameIndex(window.name)
	parent.layer.close(index);
  	parent.layer.msg('您的问题已发布', {
        icon: 1,
        shade:0.5,
        time: 2000 //2秒关闭（如果不配置，默认是3秒）
    });
}
window.onload= function(){
	var linkList=window.parent.document.getElementsByTagName("link");//获取父窗口link标签对象列表
	var head=document.getElementsByTagName("head").item(0);
	//外联样式
	for(var i=0;i<linkList.length;i++){
	var l=document.createElement("link");
		l.rel = 'stylesheet'
		l.type = 'text/css'; 
		l.href=linkList[i].href;
		head.appendChild(l);
	}
}

</script>
</body>
</html>
